package com.john.pplay.util;

import android.content.Context;
import android.content.SharedPreferences;

public class Setting {
    public static final int FIT = 0;
    public static final int REAL = 1;
    public static final int FULL = 2;

    public static final int SOFTDECODE = 0;
    public static final int HARDDECODE = 1;

    private int measureType;
    private int decodeType;
    private static Setting instance;
    private SharedPreferences sp;
    private static final String spName = "PplayData";

    private Setting(){

    };

    public static Setting getInstance(){
        if (instance == null){
            synchronized (Setting.class){
                if (instance == null){
                    instance = new Setting();
                }
            }
        }
        return instance;
    }

    public int getMeasureType() {
        return measureType;
    }

    public void setMeasureType(int measureType) {
        this.measureType = measureType;
    }

    public int getDecodeType() {
        return decodeType;
    }

    public void setDecodeType(int decodeType) {
        this.decodeType = decodeType;
    }

    public void load(Context context){
        sp = context.getSharedPreferences(spName,Context.MODE_PRIVATE);
        if (sp == null)
            return;
        measureType = sp.getInt("measureType",FIT);
        decodeType = sp.getInt("decodeType",HARDDECODE);
    }

    public void save(){
        if (sp == null)
            return;
        SharedPreferences.Editor editor = sp.edit();
        editor.putInt("measureType",measureType);
        editor.putInt("decodeType",decodeType);
        editor.commit();
    }
}
